//
//  MyMeetingGateway.swift
//  CleanArchitecture
//
//  Created by siri on 2024/11/6.
//  Copyright © 2024 Tuan Truong. All rights reserved.
//

//
//  ProductGateway.swift
//  CleanArchitecture
//
//  Created by Tuan Truong on 7/14/20.
//  Copyright © 2020 Tuan Truong. All rights reserved.
//

import Combine
import Foundation
import Factory
import APIService

// 定义网关协议
protocol MyMeetingGatewayProtocol {
    func getMyMonthMeeting(appointDate:String) -> AnyPublisher<Res<MyMonthMeetingsOutVO>, Error>
    func getMyDayMeeting(appointDate:String) -> AnyPublisher<Res<MyDayMeetingsOutVO>, Error>
}

// 定义网关实现类
struct MyMeetingGateway: MyMeetingGatewayProtocol {
    func getMyMonthMeeting(appointDate:String) -> AnyPublisher<Res<MyMonthMeetingsOutVO>, Error> {
        APIServices.default
            .request(MyMeetingEndpoint.findMyMonthMeetings(appointDate: appointDate) )
            .data(type: Res<MyMonthMeetingsOutVO>.self)
            .map {
                $0
            }.eraseToAnyPublisher()
    }
    
    func getMyDayMeeting(appointDate:String) -> AnyPublisher<Res<MyDayMeetingsOutVO>, Error> {
        APIServices.default
            .request(MyMeetingEndpoint.findMyDayMeetingsInfo(appointDate: appointDate) )
            .data(type: Res<MyDayMeetingsOutVO>.self)
            .map {
                $0
            }.eraseToAnyPublisher()
    }
}

// 预览的数据
//struct PreviewMyMeetingGateway: MyMeetingGatewayProtocol {
//    func getMyMeeting() -> AnyPublisher<[MyMeeting], Error> {
//        Future<[MyMeeting], Error> { promise in
//            let meetings = [
//                MyMeeting(name: "iPhone", price: 999),
//                MyMeeting(name: "MacBook", price: 2999)
//            ]
//            
//            promise(.success(meetings))
//        }
//        .eraseToAnyPublisher()
//    }
//}

extension Container {
    var myMeetingGateway: Factory<MyMeetingGatewayProtocol> {
        Factory(self) { MyMeetingGateway() }
//            .onPreview {
//                PreviewMyMeetingGateway()
//            }
    }
}
